Skip to content

Add host.docker.internal and host.containers.internal to the dev cert SAN #61265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

benjaminpetit
Copy link
Member

@benjaminpetit benjaminpetit commented Apr 1, 2025

Add host.docker.internal and host.containers.internal to the dev cert SAN

Add necessary SAN for dev container scenario and add an easy to parse output to the dev-certs command.

Description

  • Add host.docker.internal and host.containers.internal to the dev cert SAN.
  • Bump the certificate version to 3
  • Decouple the notion of generated certificate number and minimum acceptable certificate version
  • Add new command similar to --check --trust but with json output: --check-json-output

The notion of minimum version is important if/when we backport this feature into dotnet 8 and 9: the runtime in 8 or 9 should be able to run perfectly fine without the new SAN in the cert.

Example of output for a v2 certificate (generated with .NET 9):

[
  {
    "Thumbprint": "D17F51D47E3D8A4FAB0A964B136BF677E469CFB8",
    "Subject": "CN=localhost",
    "X509SubjectAlternativeNameExtension": [
      "localhost"
    ],
    "Version": 2,
    "ValidityNotBefore": "2025-04-02T17:45:49+02:00",
    "ValidityNotAfter": "2026-04-02T17:45:49+02:00",
    "IsHttpsDevelopmentCertificate": true,
    "IsExportable": true,
    "TrustLevel": "Full"
  }
]

Example of output for a v3 certificate:

[
  {
    "Thumbprint": "4C743A4A6588E7C34BEC70DFF7E1A8605D3D68C9",
    "Subject": "CN=localhost",
    "X509SubjectAlternativeNameExtension": [
      "localhost",
      "host.docker.internal",
      "host.containers.internal"
    ],
    "Version": 3,
    "ValidityNotBefore": "2025-04-02T17:51:51+02:00",
    "ValidityNotAfter": "2026-04-02T17:51:51+02:00",
    "IsHttpsDevelopmentCertificate": true,
    "IsExportable": true,
    "TrustLevel": "Full"
  }
]

Fixes #61155

Add new SAN for dev cert + json output for the tool
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Apr 1, 2025
@adityamandaleeka
Copy link
Member

Looks good so far!

@benjaminpetit benjaminpetit marked this pull request as ready for review April 2, 2025 16:02
@benjaminpetit benjaminpetit requested a review from Copilot April 3, 2025 16:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the certificate generation functionality to include "host.docker.internal" and "host.containers.internal" in the SAN, bumps the certificate version to 3, and adds a new command for JSON output of certificate information.

  • Introduces the new --check-json-output option and its logic
  • Refactors certificate version handling by separating generated version and minimum acceptable version
  • Updates tests and adjusts access modifiers in platform-specific certificate managers

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

File Description
src/Tools/dotnet-dev-certs/src/Program.cs Adds new JSON output option and updates certificate filtering on OSX
src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs Updates tests to use the new MinimumAspNetHttpsCertificateVersion property
src/Shared/CertificateGeneration/WindowsCertificateManager.cs, UnixCertificateManager.cs, MacOSCertificateManager.cs Adjusts access modifiers for the IsExportable method
src/Shared/CertificateGeneration/CertificateManager.cs Bumps certificate version constants, adds new SAN entries, and introduces the MinimumAspNetHttpsCertificateVersion property

@adityamandaleeka
Copy link
Member

Test failure is real.

@@ -110,6 +114,10 @@ public static int Main(string[] args)
"Display warnings and errors only.",
CommandOptionType.NoValue);

var checkJsonOutput = c.Option("--check-trust-machine-readable",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DamianEdwards is this good? Last chance to change it 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the option to enable the JSON output? Is there not a prior art we can use from the CLI already? @baronfel

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--format json is what we've been doing for most of these. the 'default' format by comparison is text.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--format json is what we've been doing for most of these. the 'default' format by comparison is text.

This option is already used for the certificate export operation. What about --output-format instead? I don't think reusing the same option is a good idea

Copy link
Member

@adityamandaleeka adityamandaleeka Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

output-format is fine with me. Or if we're not going to have any other dev-certs operations support different output types anytime soon, we can just go with --check-trust-machine-readable for now. If that changes in the future and we want more operations to be able to specify output format, we can figure out the consistency story with --format at that point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep let's not block on this given --format conflicts with the existing option for certificate export format.

Copy link
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add host.docker.internal and host.containers.internal to the dev cert SAN
4 participants